package com.shujia.core

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Demo14Union {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
    conf.setAppName("Demo14Union")
    conf.setMaster("local")

    val sc: SparkContext = new SparkContext(conf)
    val stuLineRDD: RDD[String] = sc.textFile("Spark/data/students.txt")

    val sampleRDD1: RDD[String] = stuLineRDD.sample(withReplacement = false, 0.01, seed = 100)
    val sampleRDD2: RDD[String] = stuLineRDD.sample(withReplacement = false, 0.01, seed = 200)

    // union 转换算子，两个相同类型的RDD才能够进行union，union操作得到的新的RDD的分区数等于两个RDD分区数之和
    val unionRDD: RDD[String] = sampleRDD1.union(sampleRDD2)

    unionRDD.foreach(println)




  }

}
